package com.dragon.refect.clazz;

import java.util.ArrayList;
import java.util.LinkedList;

/**
 * getName(): 如果是一个类或者接口则返回此类的全限定名(com.dragon.refect.clazz.Person)，如果是一个数组，则返回[com.dragon.refect.clazz.Person、[I;
 * 如果是原始类型，则返回void, boolean ,char, double
 *
 * getSimpleName(): 直接返回源代码中的名字，比如Person 、 int[] 、 ArrayList 、 boolean 、char
 *
 * getTypeName(): 返回源码中类型的全限定名: com.dragon.refect.clazz.Person 、 int[] 、 com.dragon.refect.clazz.Person[]
 * @author dragon
 * @since 2019/12/1
 */
public class ClassGetNameTest {

    public static void main(String[] args) {
        Class c = Person.class;
        System.out.println("Person.class.getName: " + c.getName());
        System.out.println("Person.class.getSimpleName: " + c.getSimpleName()) ;
        System.out.println("Person.class.getTypeName: " + c.getTypeName()) ;

        System.out.println("void.class.getName: " + void.class.getName());
        System.out.println("void.class.getSimpleName: " + void.class.getSimpleName());
        System.out.println("void.class.getTypeName: " + void.class.getTypeName());

        int[] array = new int[20];
        System.out.println("intArray.class.getName: " + array.getClass().getName());
        System.out.println("intArray.class.getSimpleName: " + array.getClass().getSimpleName());
        System.out.println("intArray.class.getTypeName: " + array.getClass().getTypeName());

        Person[] personArray = new Person[1];
        System.out.println("personArray.class.getName: " + personArray.getClass().getName());
        System.out.println("personArray.class.getSimpleName: " + personArray.getClass().getSimpleName());
        System.out.println("personArray.class.getTypeName: " + personArray.getClass().getTypeName());

        boolean[] bArray = new boolean[1];
        System.out.println("booleanArray.class.getName:" + bArray.getClass().getName());
        System.out.println("booleanArray.class.getSimpleName:" + bArray.getClass().getSimpleName());
        System.out.println("booleanArray.class.getTypeName:" + bArray.getClass().getTypeName());

        System.out.println("int.class.getName: " + int.class.getName());
        System.out.println("int.class.getSimpleName: " + int.class.getSimpleName());
        System.out.println("int.class.getTypeName: " + int.class.getTypeName());

        System.out.println("char.class.getName: " + char.class.getName());
        System.out.println("char.class.getSimpleName: " + char.class.getSimpleName());
        System.out.println("char.class.getTypeName: " + char.class.getTypeName());

        System.out.println("boolean.class.getName: " + boolean.class.getName());
        System.out.println("boolean.class.getSimpleName: " + boolean.class.getSimpleName());
        System.out.println("boolean.class.getTypeName: " + boolean.class.getTypeName());

        System.out.println(ArrayList.class.getName());
        System.out.println(ArrayList.class.getSimpleName());
        System.out.println(ArrayList.class.getTypeName());

        LinkedList<String> list = new LinkedList<>();
        System.out.println(list.getClass().getTypeName());

        Person p1 = new Person<String>(){

        };

        System.out.println("---------" + p1.getClass().getSimpleName());

    }
}
